/*
 * @Author: humengchuan 531537052@qq.com
 * @Date: 2024-10-15 11:38:47
 * @LastEditors: humengchuan 531537052@qq.com
 * @LastEditTime: 2024-10-15 11:46:09
 * @FilePath: \projecte:\学习\react\react-optimize-ts\src\utils\withRouter.tsx
 * @Description: 高阶组件--类组件v5路由跳转
 * 使用方式: export default withRouter(Home) 包裹类组件
 * this.props.history.push('/home')
 */
import React from 'react'
import { useNavigate, useLocation, useParams } from 'react-router-dom'

export default function withRouter(Component: any) {
    return function (props: any) {
        const push = useNavigate()
        const location = useLocation()
        const params = useParams()

        return <Component {...props} history={{ push, location, params }} />
    }
}
